-
Notifications
You must be signed in to change notification settings - Fork 15
Hlsl path tracer #224
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Hlsl path tracer #224
Conversation
| template<typename RNG> | ||
| struct Uniform1D | ||
| { | ||
| using rng_type = RNG; | ||
| using return_type = uint32_t; | ||
|
|
||
| static Uniform1D<RNG> construct(uint32_t2 seed) | ||
| { | ||
| Uniform1D<RNG> retval; | ||
| retval.rng = rng_type::construct(seed); | ||
| return retval; | ||
| } | ||
|
|
||
| return_type operator()() | ||
| { | ||
| return rng(); | ||
| } | ||
|
|
||
| rng_type rng; | ||
| }; | ||
|
|
||
| template<typename RNG> | ||
| struct Uniform3D | ||
| { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would make sense to just template it on dimensions count
| pathtracer.randGen = randgen_type::create(scramblebuf[coords].rg); // TODO concept this create | ||
| pathtracer.randGen = randgen_type::construct(scramblebuf[coords].rg); // TODO concept this create |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we call our pseudo constructors create not construct
| #ifndef _NBL_HLSL_EXT_ACCUMULATOR_INCLUDED_ | ||
| #define _NBL_HLSL_EXT_ACCUMULATOR_INCLUDED_ | ||
|
|
||
| #include <nbl/builtin/hlsl/vector_utils/vector_traits.hlsl> | ||
|
|
||
| namespace Accumulator | ||
| { | ||
|
|
||
| template<typename OutputTypeVec NBL_PRIMARY_REQUIRES(concepts::FloatingPointVector<OutputTypeVec>) | ||
| struct DefaultAccumulator | ||
| { | ||
| using input_sample_type = OutputTypeVec; | ||
| using output_storage_type = OutputTypeVec; | ||
| using this_t = DefaultAccumulator<OutputTypeVec>; | ||
| using scalar_type = typename vector_traits<OutputTypeVec>::scalar_type; | ||
|
|
||
| static this_t create() | ||
| { | ||
| this_t retval; | ||
| retval.accumulation = promote<OutputTypeVec, scalar_type>(0.0f); | ||
|
|
||
| return retval; | ||
| } | ||
|
|
||
| void addSample(uint32_t sampleCount, input_sample_type _sample) | ||
| { | ||
| scalar_type rcpSampleSize = 1.0 / (sampleCount); | ||
| accumulation += (_sample - accumulation) * rcpSampleSize; | ||
| } | ||
|
|
||
| output_storage_type accumulation; | ||
| }; | ||
|
|
||
| } | ||
|
|
||
| #endif |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this needs to move to Nabla, somewhere in the path_tracing namespace
| namespace nbl | ||
| { | ||
| namespace hlsl | ||
| { | ||
| namespace path_tracing | ||
| { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no namespace for the example
| #ifndef _NBL_HLSL_PATHTRACING_CONCEPTS_INCLUDED_ | ||
| #define _NBL_HLSL_PATHTRACING_CONCEPTS_INCLUDED_ | ||
|
|
||
| #include <nbl/builtin/hlsl/concepts.hlsl> | ||
|
|
||
| namespace nbl | ||
| { | ||
| namespace hlsl | ||
| { | ||
| namespace path_tracing | ||
| { | ||
| namespace concepts | ||
| { | ||
|
|
||
| #define NBL_CONCEPT_NAME RandGenerator | ||
| #define NBL_CONCEPT_TPLT_PRM_KINDS (typename) | ||
| #define NBL_CONCEPT_TPLT_PRM_NAMES (T) | ||
| #define NBL_CONCEPT_PARAM_0 (rand, T) | ||
| NBL_CONCEPT_BEGIN(1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this whole header needs get moved to Nabla
| #else | ||
| nbl::hlsl::float32_t4x4 invMVP; | ||
| nbl::hlsl::float32_t3x4 generalPurposeLightMatrix; | ||
| #endif |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you not just use this version for both langs ?
| #ifndef __HLSL_VERSION | ||
| #include "matrix4SIMD.h" | ||
| #endif |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
whats this for ?
| #ifndef _NBL_HLSL_PATHTRACER_RENDER_RWMC_COMMON_INCLUDED_ | ||
| #define _NBL_HLSL_PATHTRACER_RENDER_RWMC_COMMON_INCLUDED_ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wrong header guard, this is example's source
| #ifndef _NBL_HLSL_PATHTRACER_RENDER_COMMON_INCLUDED_ | ||
| #define _NBL_HLSL_PATHTRACER_RENDER_COMMON_INCLUDED_ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wrong header guard, this is example's source
| #ifndef _NBL_HLSL_PATHTRACER_RWMC_GLOBAL_SETTINGS_COMMON_INCLUDED_ | ||
| #define _NBL_HLSL_PATHTRACER_RWMC_GLOBAL_SETTINGS_COMMON_INCLUDED_ | ||
| #include "nbl/builtin/hlsl/cpp_compat.hlsl" | ||
|
|
||
| NBL_CONSTEXPR uint32_t CascadeCount = 6u; | ||
|
|
||
| #endif |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
kinda silly having one header just for this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
kick it into the main common file
| Shape<scalar_type, PST_SPHERE> light_spheres[1]; | ||
| Shape<scalar_type, PST_TRIANGLE> light_triangles[1]; | ||
| Shape<scalar_type, PST_RECTANGLE> light_rectangles[1]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you shouldn't need unused members if you have getters
| if (ImGui::IsKeyPressed(ImGuiKey_S) && params.allowedOp & ImGuizmo::OPERATION::SCALE) // for triangle/rectangle | ||
| mCurrentGizmoOperation = ImGuizmo::SCALE_X | ImGuizmo::SCALE_Y; | ||
|
|
||
| #if 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
whats this if 0 about?
| #ifndef __HLSL_VERSION | ||
| #include "matrix4SIMD.h" | ||
| #endif |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove the include, not needed
| struct RenderRWMCPushConstants | ||
| { | ||
| RenderPushConstants renderPushConstants; | ||
| nbl::hlsl::rwmc::SplattingParameters splattingParameters; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the splatting params shoul have never been compressed in Nabla, they should have been compressed here, and a getter/setter method here too
| #ifdef PERSISTENT_WORKGROUPS | ||
| #include "nbl/builtin/hlsl/math/morton.hlsl" | ||
| #endif |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no needed
|
|
||
| float32_t3 color = resolve(accessor, int16_t2(coords.x, coords.y)); | ||
|
|
||
| //float32_t3 color = rwmc::reweight<rwmc::ResolveAccessorAdaptor<float> >(pc.resolveParameters, cascade, coords); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove commented code
| #ifndef _NBL_HLSL_PATHTRACER_RESOLVE_COMMON_INCLUDED_ | ||
| #define _NBL_HLSL_PATHTRACER_RESOLVE_COMMON_INCLUDED_ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wrong header guard, this is userspace code
|
|
||
| struct ResolvePushConstants | ||
| { | ||
| uint32_t sampleCount; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unused variable
| RenderRWMCPushConstants rwmcPushConstants; | ||
| RenderPushConstants pc; | ||
| ResolvePushConstants resolvePushConstants; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't you rebuild them every frame from imgui stuff + camera etc?
Maybe lets not store them around as global state and have them transient
| std::array<smart_refctd_ptr<IGPUComputePipeline>, E_LIGHT_GEOMETRY::ELG_COUNT> m_PTGLSLPipelines; | ||
| std::array<smart_refctd_ptr<IGPUComputePipeline>, E_LIGHT_GEOMETRY::ELG_COUNT> m_PTHLSLPipelines; | ||
| std::array<smart_refctd_ptr<IGPUComputePipeline>, E_LIGHT_GEOMETRY::ELG_COUNT> m_PTGLSLPersistentWGPipelines; | ||
| std::array<smart_refctd_ptr<IGPUComputePipeline>, E_LIGHT_GEOMETRY::ELG_COUNT> m_PTHLSLPersistentWGPipelines; | ||
| std::array<smart_refctd_ptr<IGPUComputePipeline>, E_LIGHT_GEOMETRY::ELG_COUNT> m_PTHLSLPipelinesRWMC; | ||
| std::array<smart_refctd_ptr<IGPUComputePipeline>, E_LIGHT_GEOMETRY::ELG_COUNT> m_PTHLSLPersistentWGPipelinesRWMC; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can delete GLSL code now
| void updatePathtracerPushConstants() | ||
| { | ||
| // disregard surface/swapchain transformation for now | ||
| const auto viewProjectionMatrix = m_camera.getConcatenatedMatrix(); | ||
| // TODO: rewrite the `Camera` class so it uses hlsl::float32_t4x4 instead of core::matrix4SIMD | ||
| core::matrix4SIMD invMVP; | ||
| viewProjectionMatrix.getInverseTransform(invMVP); | ||
| if (useRWMC) | ||
| { | ||
| memcpy(&rwmcPushConstants.renderPushConstants.invMVP, invMVP.pointer(), sizeof(rwmcPushConstants.renderPushConstants.invMVP)); | ||
| rwmcPushConstants.renderPushConstants.generalPurposeLightMatrix = hlsl::float32_t3x4(transpose(m_lightModelMatrix)); | ||
| rwmcPushConstants.renderPushConstants.depth = depth; | ||
| rwmcPushConstants.renderPushConstants.sampleCount = resolvePushConstants.sampleCount = spp; | ||
| rwmcPushConstants.renderPushConstants.pSampleSequence = m_sequenceBuffer->getDeviceAddress(); | ||
| //rwmcPushConstants.splattingParameters.log2Start = std::log2(rwmcStart); | ||
| //rwmcPushConstants.splattingParameters.log2Base = std::log2(rwmcBase); | ||
| float32_t2 packLogs = float32_t2(std::log2(rwmcStart), std::log2(rwmcBase)); | ||
| rwmcPushConstants.splattingParameters.packedLog2 = hlsl::packHalf2x16(packLogs); | ||
| } | ||
| else | ||
| { | ||
| memcpy(&pc.invMVP, invMVP.pointer(), sizeof(pc.invMVP)); | ||
| pc.generalPurposeLightMatrix = hlsl::float32_t3x4(transpose(m_lightModelMatrix)); | ||
| pc.sampleCount = spp; | ||
| pc.depth = depth; | ||
| pc.pSampleSequence = m_sequenceBuffer->getDeviceAddress(); | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can move into a lambda somwhere in workLoopBody
| float rwmcMinReliableLuma; | ||
| float rwmcKappa; | ||
| float rwmcStart; | ||
| float rwmcBase; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
gather them up, make nicer create methods for splatting and resolve params
see #218 (comment)
@keptsecret after you merge
masteragain, you'll probably have the UI mess up and show changed from the merge commit, so close and reopen againTODO